package com.motu.monstercity.server.game.logic;

import com.motu.monstercity.server.game.commondata.maintask.TaskAchieve;
import com.motu.monstercity.server.game.userdata.*;
import com.motu.vertx.module.utility.model.EntityManager;
import com.motu.vertx.module.utility.model.Model;
import io.vertx.core.json.JsonArray;
import io.vertx.ext.auth.User;

import java.util.ArrayList;
import java.util.List;

public class MainTaskUserData extends MainTaskBaseData {
    // 获取用户主线任务,成就,城市升级任务的进度值
    public static UserTaskValue getUserTaskValue(long userId, TaskAchieve taskAchieve) {
        if (taskAchieve == null) {
            return null;
        }
        long taskId = MainTaskManager.getTaskId(taskAchieve.getTaskType(), taskAchieve.getParam());
        return getUserTaskValue(userId, taskId);
    }

    public static UserTaskValue getUserTaskValue(long userId, long taskId) {
        Model model = EntityManager.getEntity(UserTaskValue.class, userId, taskId);
        return (UserTaskValue) model;
    }

    public static UserCityTaskReward getUserCityTaskReward(long userId, long taskId) {
        return (UserCityTaskReward) EntityManager.getEntity(UserCityTaskReward.class, userId, taskId);
    }

    // 获取UserAchieve列表
    public static List<UserCityTaskReward> getUserCityTaskRewardList(long userId) {
        List<UserCityTaskReward> list = new ArrayList<>();
        for (Model model : EntityManager.getEntityList(UserCityTaskReward.class, userId)) {
            UserCityTaskReward entity = (UserCityTaskReward) model;
            list.add(entity);
        }
        return list;
    }

    public static List<UserTaskValue> getUserTaskValueList(long userId) {
        List<UserTaskValue> list = new ArrayList<>();
        for (Model model : EntityManager.getEntityList(UserTaskValue.class, userId)) {
            UserTaskValue entity = (UserTaskValue) model;
            list.add(entity);
        }
        return list;
    }

    public static UserMainTask getUserMainTask(long userId, long taskId) {
        return (UserMainTask) EntityManager.getEntity(UserMainTask.class, userId, taskId);
    }

    // 获取UserMainTask列表
    public static List<UserMainTask> getUserMainTaskList(long userId) {
        List<UserMainTask> list = new ArrayList<>();
        for (Model model : EntityManager.getEntityList(UserMainTask.class, userId)) {
            UserMainTask entity = (UserMainTask) model;
            list.add(entity);
        }
        return list;
    }

    public static UserAchieve getUserAchieve(long userId, long taskId) {
        UserAchieve userAchieve = (UserAchieve) EntityManager.getEntity(UserAchieve.class, userId, taskId);
        if (userAchieve == null) {
            userAchieve = new UserAchieve();
            userAchieve.putUserId(userId);
            userAchieve.putTaskId(taskId);
            userAchieve.doCreate();
        }
        return userAchieve;
    }

    // 获取UserAchieve列表
    public static List<UserAchieve> getUserAchieveList(long userId) {
        List<UserAchieve> list = new ArrayList<>();
        for (Model model : EntityManager.getEntityList(UserAchieve.class, userId)) {
            UserAchieve entity = (UserAchieve) model;
            list.add(entity);
        }
        return list;
    }


    public static UserDayTask getUserDayTask(long userId, long taskId) {
        return (UserDayTask) EntityManager.getEntity(UserDayTask.class, userId, taskId);
    }

    // 获取UserDayTask列表
    public static List<UserDayTask> getUserDayTaskList(long userId) {
        List<UserDayTask> list = new ArrayList<>();
        for (Model model : EntityManager.getEntityList(UserDayTask.class, userId)) {
            UserDayTask entity = (UserDayTask) model;
            list.add(entity);
        }
        return list;
    }

    public static UserHonor getUserHonor(long userId, int honorType) {
        return (UserHonor) EntityManager.getEntity(UserHonor.class, userId, honorType);
    }

    // 获取UserHonor列表
    public static List<UserHonor> getUserHonorList(long userId) {
        List<UserHonor> list = new ArrayList<>();
        for (Model model : EntityManager.getEntityList(UserHonor.class, userId)) {
            UserHonor entity = (UserHonor) model;
            list.add(entity);
        }
        return list;
    }

    public static UnionHonor getUnionHonor(long unionId, int honorType) {
        return (UnionHonor) EntityManager.getEntity(UnionHonor.class, unionId, honorType);
    }
    public static List<UnionHonor> getUnionHonorList(long unionId) {
        List<UnionHonor> list = new ArrayList<>();
        for (Model model : EntityManager.getEntityList(UnionHonor.class, unionId)) {
            UnionHonor entity = (UnionHonor) model;
            list.add(entity);
        }
        return list;
    }

    public static ServerHonor getServerHonor(int serverId, long honorId) {
        return (ServerHonor) EntityManager.getEntity(ServerHonor.class, serverId, honorId);
    }

    // 获取ServerHonor列表
    public static List<ServerHonor> getServerHonorList(int serverId) {
        List<ServerHonor> list = new ArrayList<>();
        for (Model model : EntityManager.getEntityList(ServerHonor.class, serverId)) {
            ServerHonor entity = (ServerHonor) model;
            list.add(entity);
        }
        return list;
    }
}
